package easytalk.views.custom;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.KeyListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.forms.widgets.FormToolkit;

import easytalk.media.EasyTalkImages;

public class MessageEditor  {

	private Text 		editText;
	private Composite 	composite;

	public Composite getComposite() {
		return composite;
	}


	public void setComposite(Composite composite) {
		this.composite = composite;
	}


	public MessageEditor(final Composite parent, int style, FormToolkit toolkit) {
		composite = toolkit.createComposite(parent,SWT.WRAP);
		GridLayout gridLayout = new GridLayout(3, false);
		gridLayout.marginWidth = 5;
		gridLayout.marginHeight = 5;
		gridLayout.verticalSpacing = 0;
		gridLayout.horizontalSpacing = 0;
		composite.setLayout(gridLayout);

		Button smileyButton = toolkit.createButton(composite, Messages.getString("MessageEditor.1"), SWT.PUSH) ; //$NON-NLS-1$
		smileyButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true,	false));
		smileyButton.setImage(EasyTalkImages.TINY_SMILEY);	
		smileyButton.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				SmileyDialog dialog = new SmileyDialog(parent.getShell());	
				dialog.open();
				super.widgetSelected(e);
			}
		});



	/*	Button sendButton = toolkit.createButton(composite, "send", SWT.PUSH);
		sendButton.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false,
				false));
		*/
		
		Button setAutoButton = toolkit.createButton(composite, Messages.getString("MessageEditor.3"), SWT.PUSH); //$NON-NLS-1$
		setAutoButton.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false,false));
		
		
		Button recieveButton = toolkit.createButton(composite, Messages.getString("MessageEditor.4"), SWT.CHECK); //$NON-NLS-1$
		recieveButton.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false,true,1,2));

		editText = toolkit.createText(composite, Messages.getString("MessageEditor.2"), SWT.SINGLE | SWT.LEAD | SWT.BORDER) ; //$NON-NLS-1$
		editText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 3,1));
	}

	
	public void addKeyListener(KeyListener listener) {
		editText.addKeyListener(listener);
	}

	public String getText() {
		return editText.getText();
	}

	public void setText(String text) {
		this.editText.setText(text);
	}


	public void setVisible(boolean visible) {
		composite.setVisible(visible);
		
	}
}
